package leetcode.l0614;

import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author Retain
 * @date 2021/6/14 20:39
 */
public class Medium_子集_78 {

    public static void main(String[] args) {
        new PriorityQueue<>();
        Medium_子集_78 p = new Medium_子集_78();
        p.subsets(new int[]{1,2,3});
    }
    /**
     * 基础的回溯法，但是要求不重复.通过下标的控制，类似全排列，开始下标依次+1，与后面的数进行组合
     * @param nums
     * @return
     */
    List<List<Integer>> res = new ArrayList<>();
    public List<List<Integer>> subsets(int[] nums) {
        backTrack(nums,0,new ArrayList<>());
        return res;
    }

    public void backTrack(int[] nums,int start, List<Integer> track) {

        res.add(new ArrayList<>(track));
        for (int i = start; i < nums.length; i++) {
            track.add(nums[i]);
            backTrack(nums,i+1,track);
            track.remove(track.size() - 1);
        }
    }
}
